#pragma once

#ifndef INC_02_INSERT_SORT_H
#define INC_02_INSERT_SORT_H

#include <iostream>
#include <algorithm>
#include "TestSortHelper.h"

using namespace std;

template <typename T>
void insertSort(T arrays[], int lenarray) {
	for (int i = 1; i < lenarray; i++) {
		/*for (int j = i; j > 0; j--) {
			if (arrays[j] < arrays[j-1]) {
				swap(arrays[j-1], arrays[j]);
			}
			else {
				break;
			}
		}*/

		T temple = arrays[i];
		int j = i;
		for (; j > 0 && temple <arrays[j-1];j--) {
			arrays[j] = arrays[j - 1];
		}
		arrays[j] = temple;

	}
}

template <typename T>
void insertSort(T arrays[], int left, int right) {
	for (int i = left; i <= right; i++) {
		T temple = arrays[i];
		int j = i;
		for (; j > left && temple < arrays[j - 1];j--) {
			arrays[j] = arrays[j - 1];
		}
		arrays[j] = temple;
	}
}
#endif